<template>
  <div style="display: none">
    <div style="width: 500px">{{ data }}</div>
    <form :action="data.AssertionConsumerUrl" method="post" ref="submit">
      <p>账号：<input type="text" name="RelayState" :value="data.RelayState" /></p>
      <p>密码：<input type="text" name="SAMLResponse" :value="data.SAMLResponse" /></p>
    </form>
  </div>
</template>

<script lang="ts" setup>
  import userService from '@/api/userService'
  import { useRoute } from 'vue-router'
  import VueCookies from 'vue-cookies'
  const route = useRoute()
  let data = reactive<any>({})
  const params = route.query
  const cookie: any = VueCookies
  const submit = ref()

  userService
    .samlLogin(
      params.RelayState as string,
      params.SAMLRequest as string,
      params.SigAlg as string,
      params.Signature as string,
      localStorage.getItem('userId') as string,
      cookie.get('token')
    )
    .then((res) => {
      data.length = 0
      data = res.data.data
      if (data.RelayState && data.SAMLResponse) {
        nextTick().then(() => {
          submit.value.submit()
        })
      }
    })
</script>
